package tools;

import java.util.Collection;
import java.util.Iterator;

public class StringOp {
	/**
	 * Join a list of Strings by inserting a join string between each of them.
	 * 
	 * @param s Collection of Strings to join
	 * @param delimiter String to place between each item
	 * @return joined String
	 */
	public static String join(Collection<?> s, String delimiter) {
		// Adapted from: http://snippets.dzone.com/posts/show/91
        StringBuffer buffer = new StringBuffer();
        Iterator<?> iter = s.iterator();
        while (iter.hasNext()) {
            buffer.append(iter.next());
            if (iter.hasNext()) {
                buffer.append(delimiter);
            }
        }
        return buffer.toString();
    }
}
